﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;

namespace BlockMain_Class
{
    public static class HttpHelper
    {
        /// <summary>
        /// POST Text
        /// </summary>
        /// <param name="postUrl"></param>
        /// <param name="paramData"></param>
        /// <param name="dataEncode"></param>
        /// <returns></returns>
        public static string PostWebRequest(string postUrl, string paramData, System.Text.Encoding dataEncode = null)
        {
            string result = string.Empty;
            try
            {
                ServicePointManager.Expect100Continue = false;
                if (dataEncode == null)
                {
                    dataEncode = System.Text.Encoding.UTF8;
                }
                byte[] bytes = dataEncode.GetBytes(paramData);
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                httpWebRequest.ContentLength = (long)bytes.Length;
                System.IO.Stream requestStream = httpWebRequest.GetRequestStream();
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Close();
                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                System.IO.StreamReader streamReader = new System.IO.StreamReader(httpWebResponse.GetResponseStream(), System.Text.Encoding.UTF8);
                result = streamReader.ReadToEnd();
                streamReader.Close();
                httpWebResponse.Close();
                requestStream.Close();
            }
            catch (System.Exception e)
            {
                //错误日志
                
            }
            return result;
        }



    }
}